//
//  ViewController.m
//  14-HomeWork
//
//  Created by dllo on 16/8/2.
//  Copyright © 2016年 LST. All rights reserved.
//

#import "ViewController.h"
#import "NewCollectionViewCell.h"
#import "NewCollectionReusableView.h"
#import "TopView.h"
#define COLORAUTO [UIColor colorWithRed:(arc4random() % 256 / 255.0) green:(arc4random() % 256 / 255.0 )blue:(arc4random() % 256 / 255.0) alpha:1.0]

@interface ViewController ()<UICollectionViewDelegate, UICollectionViewDataSource>
@property (nonatomic, strong)UISegmentedControl *segement;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    [self creatSegment];
    [self creatCollectionView];
}
- (void)creatSegment {
_segement = [[UISegmentedControl alloc] initWithItems:@[@"攻略", @"单品"]];
_segement.frame = CGRectMake(90, 20, self.view.frame.size.width -180, 30);
_segement.selectedSegmentIndex = 0;
_segement.tintColor = [UIColor colorWithRed:0.94 green:0.41 blue:0.38 alpha:1.00];
[self.segement  addTarget:self action:@selector(click:) forControlEvents:UIControlEventValueChanged];
self.navigationItem.titleView = _segement;
[self.navigationController.navigationBar setTitleTextAttributes:
 @{NSFontAttributeName:[UIFont systemFontOfSize:23],
   NSForegroundColorAttributeName:[UIColor whiteColor]}];
self.navigationController.navigationBar.tintColor = [UIColor colorWithRed:0.94 green:0.41 blue:0.38 alpha:1.00];

}
- (void)creatCollectionView {
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
    layout.itemSize = CGSizeMake(self.view.bounds.size.width / 2 - 5, 100);
    layout.minimumLineSpacing = 5;
    layout.minimumInteritemSpacing = 5;
    layout.headerReferenceSize = CGSizeMake(0, 50);
    UICollectionView *collection = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height) collectionViewLayout:layout];
    collection.delegate = self;
    collection.dataSource = self;
    collection.backgroundColor = [UIColor cyanColor];
    [self.view addSubview:collection];
    collection.contentInset = UIEdgeInsetsMake(350, 0, 0, 0);
    UIView *topview = [[UIView alloc] initWithFrame:CGRectMake(0, -345, self.view.bounds.size.width, 50)];
    topview.backgroundColor = [UIColor whiteColor];
    [collection addSubview:topview];
    UILabel *left = [[UILabel alloc] initWithFrame:CGRectMake(5, 5, 60, 30)];
    left.text = @"栏目";
    [topview addSubview:left];
    UILabel *right = [[UILabel alloc] initWithFrame:CGRectMake(230, 5, 80, 30)];
    right.text = @"查看全部";
    [topview addSubview:right];
    TopView *view = [[TopView alloc] initWithFrame:CGRectMake(0, -295, self.view.bounds.size.width, 290)];
    view.backgroundColor = [UIColor grayColor];
    [collection addSubview:view];
    [collection registerClass:[NewCollectionViewCell class] forCellWithReuseIdentifier:@"cell"];
    [collection registerClass:[NewCollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"header"];
}
- (NSInteger) collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
        return 10;
}
- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    NewCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];
    //cell.contentView.backgroundColor = COLORAUTO;
   // cell.newsImage.image = [UIImage imageNamed:@"9"];
    return cell;
}
- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath {
    NewCollectionReusableView *reusableView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"header" forIndexPath:indexPath];
    reusableView.backgroundColor = [UIColor whiteColor];
    return reusableView;
}
- (void)click:(UISegmentedControl *)sender {
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
